#ifndef __MMBLOCK_H
#define __MMBLOCK_H
#include "stdtype.h"

/**
 * mmblock descriptor definition
 */
typedef struct
{
    mx_void_pt addr;        // start address of memory space
    mx_usize_t size;        // size of memory space
    mx_void_pt end;         // end address of memory space
    mx_usize_t used;        // record the size of used memory
    mx_usize_t bsize;       // block size
    mx_void_pt apointer;    // point to allocatable block
    mx_void_pt fpointer;    // point to freed block
} mx_mmblock_t, *mx_mmblock_pt;

/* initialze the mmblock */
void mx_mmblock_init (mx_mmblock_pt pmmblock, mx_void_pt addr, mx_usize_t size, mx_usize_t bsize);
/* allocate a block */
mx_void_pt mx_mmblock_alloc (mx_mmblock_pt pmmblock);
/* free a block */
void mx_mmblock_free (mx_mmblock_pt pmmblock, mx_void_pt addr);
/* free all blocks */
void mx_mmblock_freeall (mx_mmblock_pt pmmblock);
/* get the total memory of mmblock */
mx_usize_t mx_mmblock_total (mx_mmblock_pt pmmblock);
/* get the available memory of mmblock */
mx_usize_t mx_mmblock_available (mx_mmblock_pt pmmblock);
/* get the start address of memory */
mx_void_pt mx_mmblock_startaddr (mx_mmblock_pt pmmblock);
/* get the block size of mmblock */
mx_usize_t mx_mmblock_blocksize (mx_mmblock_pt pmmblock);

#endif
